package com.Fate.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Method;

@WebServlet("/page.do")
public class PageServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String tag = req.getParameter("service");
        try {
            Method m = this.getClass().getDeclaredMethod(tag, HttpServletRequest.class,HttpServletResponse.class);
            m.invoke(this,req,resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * 跳转到main.jsp
     */
    protected void main(HttpServletRequest req ,HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("WEB-INF/view/main.jsp").forward(req,resp);
    }
    /**
     * 跳转到user/list.jsp  用户列表页面
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    protected void userList(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("WEB-INF/view/user/list.jsp").forward(req,resp);
    }

    /**
     * 去客户列表页面 customer.jsp
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    protected void customerList(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            //业务员查询出来
            //放到request
        //在jsp页面 进行 for循环
        req.getRequestDispatcher("WEB-INF/view/customer/list.jsp").forward(req,resp);
    }

    /**
     * 去修改密码页面 password.jsp
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    protected void modify(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //业务员查询出来
        //放到request
        //在jsp页面 进行 for循环
        req.getRequestDispatcher("WEB-INF/system/modify/password.jsp").forward(req,resp);
    }

}
